package com.hxk.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ControllerAdvice+@ExceptionHandler 注解处理异常
 * @author Cactus
 */
@ControllerAdvice
public class MyControllerAdvice {

	@ResponseBody
	@ExceptionHandler(value=java.lang.Exception.class)
	public Map<String, Object> myException(Exception ex){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 500);
		map.put("msg", ex.toString());
		return map;
	}
	
	@ResponseBody
	@ExceptionHandler(value=java.lang.NullPointerException.class)
	public Map<String, Object> nullPointerException(Exception ex){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 500);
		map.put("msg", "空指针");
		return map;
	}
}
